﻿using SoldiHive.Core.Persistence;
using SoldiHive.Model;
using System.Collections.Generic;
using System.Linq;

namespace SoldiHive.Core.Crawlers
{
	public class RivalsCrawler : IRivalsCrawler
	{
		private ICompanyRepository companyRepository;

		public RivalsCrawler(ICompanyRepository companyRepository)
		{
			this.companyRepository = companyRepository;
		}

		public IList<Company> GetRivals(Company company)
		{
			IList<Company> rivals = Enumerable.Empty<Company>().ToList();

			if (company.SubIndustry != null)
			{
				rivals = this.companyRepository.GetCompanies(company.SubIndustry);
			}
			else if (company.Industry != null)
			{
				rivals = this.companyRepository.GetCompanies(company.Industry);
			}
			else if (company.Sector != null)
			{
				rivals = this.companyRepository.GetCompanies(company.Sector);
			}

			return rivals;
		}
	}
}
